layui.config({
    base: "static/layui/module/"
}).extend({
	dynamicCondition: 'dynamicCondition/dynamicCondition'
}).use(['form','layer','jquery','table','upload','element','dynamicCondition','laytpl'],function(){
	var form = layui.form,
		layer = layui.layer,
        $ = layui.jquery,
        table=layui.table,
        upload = layui.upload,
        element = layui.element,
        dynamicCondition=layui.dynamicCondition,
        laytpl=layui.laytpl;

	table.render({
        elem:'#table'
    	,height: 'full-140'
    	,url:'/manage/settlement_order/list'
	    ,method:'post'
        ,page: true //开启分页
	    ,limit: 10
	    ,limits: [10,15,20,30,40,50,100]
	    ,loading: true
        ,cols: [[ //表头
        	{type:'numbers', title:'序号'}
        	,{type:'checkbox'}
    		,{field: 'customerCode', title: '客户编码', minWidth:'150'}
    		,{field: 'customerName', title: '客户名称', minWidth:'150'}
    		,{field: 'customerOrder', title: '客户订单号', minWidth:'150'}
    		,{field: 'orderNo', title: '内部订单号', minWidth:'90'}
    		,{field: 'saleOrderNo', title: '销售订单号', minWidth:'90'}
    		,{field: 'parentOrderNo', title: '父级订单号', minWidth:'80'}
    		,{field: 'relatedOrder', title: '关联订单号', minWidth:'120'}
    		,{field: 'personName', title: '业务员', minWidth:'90'}
    		,{field: 'status', title: '确认结算', minWidth:'80', templet: function (d){
					return d.status?'已确认':'未确认';
				}}
			,{field: 'cls', title: '承揽商', minWidth:'90'}
			,{field: 'cplb', title: '产品类别', minWidth:'90'}
			,{field: 'ddsx', title: '订单属性', minWidth:'90'}
    		,{field: 'createTime', title: '创建时间', minWidth:'120', hide: true}
			,{fixed: 'right', title: '操作',toolbar: '#barRight'}
        ]]
    	,text: {
    		none: '暂无相关数据' //默认：无数据。注：该属性为 layui 2.2.5 开始新增
    	}
    	,toolbar:'#tableToolbar'
    	,defaultToolbar: ['filter']
		,done: function(res,curr,count){
			for(var i in res.data){
				if(!res.data[i].status){
					$("tr[data-index='"+i+"']").attr({"style":"color:red","font-weight":"bold"})
				}
			}
		}
    });

	//监听行单击事件
	table.on('rowDouble(table)', function(obj){
		top.layer.open({
			type: 2
			,title: "详情"
			,maxmin: true
			,area: ['80%', '100%']
			,content: '/manage/settlement_order/infoHtml?id='+obj.data.id
			,cancel: function(index, layero){
				table.reload('table');
			}
		});
	});
	
	var dataFields = [
		{field:"customer_code", title:"客户", edit:"select", templet:"#customer"}
		,{field:"customer_order", title:"客户订单号", edit:"text"}
		,{field:"order_no", title:"内部订单号", edit:"text"}
		,{field:"parent_order_no", title:"父级订单号", edit:"text"}
		,{field:"related_order", title:"关联订单号", edit:"text"}
		,{field:"sale_order_no", title:"销售订单号", edit:"text"}
		,{field:"status", title:"结算状态", edit:"select", templet:"#status"}
	];
	
	var dc = dynamicCondition.create({
    	fields:dataFields
	  	,tableId:"table" 
		,conditionTextId:"#findMsg"
		,type:"complex" 
	  	,requestDataType:"json"
	  	,counts:5
		,queryCallBack:function(requestData){}
	});
	
    table.on('toolbar(table)', function(obj){
    	var tableCheckData = table.checkStatus(obj.config.id).data;
		switch(obj.event){
			case 'find':
				dc.open();
			break;
		    case 'fix':
		    	if(tableCheckData.length != 1){
		    		layer.msg('请先选择一条数据');
		    		return;
				}
				top.layer.open({
					type: 2
					,title: "详情"
					,maxmin: true
					,area: ['80%', '100%']
					,content: '/manage/settlement_order/infoHtml?id='+tableCheckData[0].id
					,cancel: function(index, layero){
						table.reload('table');
					}
				});
		    break;
			case 'download':
				layer.confirm('确定要导出期初模版到本地吗？', function (index) {
					window.location.href = "/manage/settlement_order/download_templet";
					layer.close(index);
				});
				break;
			case 'addD':
				top.layer.open({
					type: 2
					,title: "新增"
					,area: ['80%', '100%']
					,btn: ['确定', '关闭']
					,content: '/manage/settlement_order/addHtml'
					,yes: function (index, layero) {
						let iframeWindow = $(layero).find("iframe")[0].contentWindow;
						iframeWindow.fromData();
						return false
					}
					,end: function (){
						table.reload('table');
					}
				});
				break;
		};
	});

	table.on('tool(table)', function(obj){
		switch(obj.event){
			case 'upd':
				top.layer.open({
					type: 2
					,title: "修改"
					,area: ['80%', '100%']
					,btn: ['确定', '关闭']
					,content: '/manage/common/editHtml/settlement_order/'+obj.data.id
					,yes: function (index, layero) {
						let iframeWindow = $(layero).find("iframe")[0].contentWindow;
						iframeWindow.fromData();
						return false
					}
					,end: function (){
						table.reload('table');
					}
				});
				break;
		}
	})

})
